import { legacy_createStore as createStore, combineReducers } from 'redux'
import { carReducer } from './car/carReducer'

// reducer
const rootReducer = combineReducers({
  car: carReducer,
})

// 仓库
const store = createStore(rootReducer)

// 获取仓库类型
export type RootState = ReturnType<typeof store.getState>

// 订阅仓库
store.subscribe(() => {
  // 获取数据
  const state = store.getState()
  // 存储数据
  localStorage.setItem('carList', JSON.stringify(state.car.carList))
})

export default store